/*
 * This file is part of VCompiler.
 * 
 * VCompiler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * VCompiler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with VCompiler.  If not, see <http://www.gnu.org/licenses/>.
 */

public class VFasm
{
	/**
	 * 
	 * @param from
	 * @param to
	 * @return
	 */
	private static String leftRight(String from, String to)
	{
		return (" " + to + ", " + from);
	}
	/**
	 * Moves 'from' to 'to'
	 * @param from A string that represents a location. Usually a register.
	 * @param to This is where the result will be in.
	 * @return Returns a valid assembly line.
	 */
	public static String mov(String from, String to)
	{
		return ("mov" + leftRight(to, from));
	}
	
	/**
	 * Pushes 'from' to the stack
	 * @param from The value that will be pushed.
	 * @return Returns a valid assembly line.
	 */
	public static String push(String from)
	{
		return ("push " + from);
	}
	/**
	 * Pops a value from the stack and puts it into 'to'
	 * @param to The location where the top stack value will be placed in.
	 * @return Returns a valid assembly line.
	 */
	public static String pop(String to)
	{
		return ("pop " + to);
	}
	
	/**
	 * Adds 'from' to 'to' and puts the result in 'to'
	 * @param from First value in the expression.
	 * @param to Second value in the expression. The result will be placed in here.
	 * @return Returns a valid assembly line.
	 */
	public static String add(String from, String to)
	{
		return ("add" + leftRight(to, from));
	}
	/**
	 * Subtracts 'from' from 'to' and puts the result in 'to'
	 * @param from First value in the expression.
	 * @param to Second value in the expression. The result will be placed in here.
	 * @return Returns a valid assembly line.
	 */
	public static String sub(String from, String to)
	{
		return ("sub" + leftRight(to, from));
	}
	
	/**
	 * Multiplies 'from' with the register EAX and puts the result in EAX
	 * @param from First value in the expression.
	 * @return Returns a valid assembly line.
	 */
	public static String mul(String from)
	{
		return ("mul" + from);
	}
	/**
	 * Divides EAX by 'from' and puts the result in EAX
	 * @param from First value in the expression.
	 * @return Returns a valid assembly line.
	 */
	public static String div(String from)
	{
		return ("cdq" + "\n" + "idiv " + from);
	}
	/**
	 * Modulus EAX by 'from' and puts the result in EAX
	 * @param from First value in the expression.
	 * @return Returns a valid assembly line.
	 */
	public static String mod(String from)
	{
		return (div(from) + "\n" + "mov eax, edx");
	}
	
	/*
	 * TODO: Add the different jumping mechanisms.
	 */
}
